<?php

namespace App\Http\Middleware;

use Closure;

/**
 * 请求方式配置中间件
 *
 * @package App\Http\Middleware
 */
class RequestMode
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        # 判断API请求方式下 追加一些配置
        $isApi = $request->is('api/*');

        if ($isApi) {
            $pathMap = require_once base_path('routes/apiadapter.php');
            config([
                'prorequest.mode'      => 'api',
                'prorequest.map'       => $pathMap,
            ]);
        } else {
            config([
                'prorequest.mode'      => 'web'
            ]);
        }

        return $next($request);
    }
}
